(function (a2dmah5) {
    a2dmah5.addExpandPage(0, function (get) {
        const Common = get('UtilsCommon', 'Common');

        return {
            expandInit() {
                this.saveEntityData2 = this.getProperty('saveEntityData2');
                const accessoryId = this.getProperty('AccessoryId');
                accessoryId.valueChange = this.accessoryIdChange.bind(this);
                this.systemNumProperty = this.getProperty('SystemNum');
                this.numProperty = this.getProperty('Num');
                this.numProperty.valueChange = this.numChange.bind(this);
                this.lostNumProperty = this.getProperty('LostNum');
            },
            accessoryIdChange(value, selectData, property) {
                if (!property.isChanged || !selectData) return;

                this.currentPrice = selectData.Price;
                const { StockNum } = selectData;
                this.systemNumProperty.setValue(StockNum);
                this.computeLostNum(Common.enlarge(StockNum, 3), null);
            },
            numChange(value) {
                this.computeLostNum(null, Common.enlarge(value, 3));
            },
            computeLostNum(systemNum, num) {
                if (systemNum === null) systemNum = Common.enlarge(this.systemNumProperty.getValue(), 3);
                if (num === null) num = Common.enlarge(this.numProperty.getValue(), 3);
                const lostNum = (systemNum - num) / 1000;
                this.lostNumProperty.setValue(lostNum);
            },
            expandSetEntityData({ entityData }) {
                entityData.Status = 0;
                if (this.currentPrice !== undefined) entityData.Price = this.currentPrice;
                return entityData;
            },
            expandDataLoad({ data }) {
                this.entityData = data;
                if ((data.Status == 0 || data.Status == 1) && Common.isEquals(data.CreateUser, this.loginUser.UserId, true)) this.saveEntityData2.setIsVisible(true);
            }
        }
    });

})(window.a2dmah5);